﻿using System;
using System.Collections.Generic;
using System.Text;

//{
//    IF (unaryHead[la.kind] || IsTypeCast())
//    (	"+"									(. tsym (t, depth); .)
//    |	"-"									(. tsym (t, depth); .)
//    |	"!"									(. tsym (t, depth); .)
//    |	"~"									(. tsym (t, depth); .)
//    |	"++"								(. tsym (t, depth); .)
//    |	"--"								(. tsym (t, depth); .)
//    |	"*"									(. tsym (t, depth); .)
//    |	"&"									(. tsym (t, depth); .)
//    |	"("									(. tsym (t, depth); .)
//      Type<out dummy, false, out ty>
//      ")"									(. tsym (t, depth); .)
//      /* Problem:  "(" Type ")" from here and	*
//       *           "(" Expr ")" from Primary  *
//       *           are not distinguishable    *
//       * Solution: (in IsTypeCast()) ARRIBA DE ESTO! */
//    )
//}


namespace HAVNet.Intros.AST
{
    public enum ASTExprUnaryHeadType
    { 
        NONE,
        PLUS,
        MINUS,
        BOOLNOT,
        BITNOT,
        PLUSPLUS,
        MINUSMINUS,
        TIMES,
        BITAND,
        CAST,
    }

    public class ASTExprUnaryHead : ASTNode
    {
        public  ASTExprUnaryHeadType    headType    { get; set; }
        public  ASTType                 castType    { get; set; }

        public ASTExprUnaryHead (ASTExprUnaryHeadType headType, ASTType castType)
        {
            this.headType = headType;
            this.castType = castType;
        }

        public ASTExprUnaryHead (ASTExprUnaryHeadType headType)
            : this (headType, null)
        { }

        public override string ToString ()
        {
            switch (headType)
            { 
                case ASTExprUnaryHeadType.PLUS      : return "+";
                case ASTExprUnaryHeadType.MINUS     : return "-";
                case ASTExprUnaryHeadType.BOOLNOT   : return "!";
                case ASTExprUnaryHeadType.BITNOT    : return "~";
                case ASTExprUnaryHeadType.PLUSPLUS  : return "++";
                case ASTExprUnaryHeadType.MINUSMINUS: return "--";
                case ASTExprUnaryHeadType.TIMES     : return "*";
                case ASTExprUnaryHeadType.BITAND    : return "&";
                case ASTExprUnaryHeadType.CAST      : return "(" + castType + ")";
            }

            return "";
        }
    }
}
